package com.example.otherincome;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "income.db";
    private static final int DATABASE_VERSION = 1;

    private static final String SQL_CREATE_ENTRIES =
            "CREATE TABLE " + DatabaseContract.IncomeEntry.TABLE_NAME + " (" +
                    DatabaseContract.IncomeEntry._ID + " INTEGER PRIMARY KEY," +
                    DatabaseContract.IncomeEntry.COLUMN_INCOME + " TEXT," +
                    DatabaseContract.IncomeEntry.COLUMN_SOURCE + " TEXT)";

    private static final String SQL_DELETE_ENTRIES =
            "DROP TABLE IF EXISTS " + DatabaseContract.IncomeEntry.TABLE_NAME;

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ENTRIES);
        final String SQL_CREATE_ENTRIES =
                "CREATE TABLE " + DatabaseContract.IncomeEntry.TABLE_NAME + " (" +
                        DatabaseContract.IncomeEntry._ID + " INTEGER PRIMARY KEY," +
                        DatabaseContract.IncomeEntry.COLUMN_INCOME + " TEXT," +
                        DatabaseContract.IncomeEntry.COLUMN_SOURCE + " TEXT)";

        final String SQL_CREATE_RECORD_ENTRIES =
                "CREATE TABLE " + DatabaseContract.IncomeEntry.IncomeRecordEntry.TABLE_NAME + " (" +
                        "CREATE TABLE " + DatabaseContract.IncomeEntry.TABLE_NAME + " (" +
                        DatabaseContract.IncomeEntry._ID + " INTEGER PRIMARY KEY," +
                        DatabaseContract.IncomeEntry.COLUMN_INCOME + " TEXT," +
                        DatabaseContract.IncomeEntry.COLUMN_TYPE + " TEXT)";

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(SQL_DELETE_ENTRIES);
        onCreate(db);
    }
}
